function login(req, res) {
    console.log("login", req.url);
    // res.end("login ok");
    const reQuerystring = /\?(.*)/;
    const qsArr = reQuerystring
        .exec(req.url)[1]
        .split("&")
        .map((keyValuePair) => {
            const [key, value] = keyValuePair.split("=");
            return { key, value };
        });
    console.log("qsArr", qsArr);

    const [{ key: ku, value: username }, { key: kp, value: password }] = qsArr;
    console.log(username, password);

    if (username === "admin" && password === "123456") {
        // 登录成功
        res.writeHead(302, [
            ["Set-Cookie", "logined=true"],
            ["Set-Cookie", `username=${username}`],
            ["Location", "/files/pages/home.html"],
        ]);
        res.end();
    } 
    
    else {
        // 登录失败
        res.writeHead(302, [
            ["Set-Cookie", "logined=false"],
            ["Location", "/files/pages/login.html"],
        ]);
        res.end();
    }
}

module.exports = {
    login,
};
